package com.tzh.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesUtils {

    private static final Properties configPro = new Properties();

    private static final Logger log = LoggerFactory.getLogger(PropertiesUtils.class);

    static {
        try (FileInputStream in = new FileInputStream("src/main/resources/config.properties");) {
            configPro.load(in);
        } catch (IOException ioException) {
            log.error("读取{}信息失败！", "config.properties");
            ioException.printStackTrace();
        }


    }

    private static Properties initProp(String fileName) {
        Properties prop = new Properties();
        FileInputStream in = null;
        try {
            in = new FileInputStream(fileName);
            prop.load(in);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
            log.error("读取信息失败！", e);
        } finally {
            log.error("读取{}信息失败！", fileName);
        }
        return configPro;
    }

    public static String getConfigValue(String key, String def) {
        String value = configPro.getProperty(key, def);
        return value;
    }
}
